#pragma once

class Task;
class Event;
class IEventHandler;
class EventChannel;

class Service
{
public:
					Service();	
	virtual			~Service();		

public:
	void			Reset();

protected:
	virtual void	OnReset() = 0;

	EventChannel*	CreateSysChannel();
	void			MakeSysTask(Task* task);
};

//////////////////////////////////////////////////////////////////////////

class EventService : public Service
{
private:
					EventService();
	virtual			~EventService();

public:
	void			RemoveHandler(IEventHandler* handler);
	
	EventChannel*	CreateChannel();
	void			RemoveChannel(EventChannel* c);

protected:	
	virtual void	OnReset();

private:
	typedef std::set<EventChannel*> ChannelSet;
	ChannelSet		m_Channels;

private:
	friend class	GameApp;
	friend class	Service;

	EventChannel*	CreateSysChannel();
	void			StepTick();
};

//////////////////////////////////////////////////////////////////////////

class TaskService : public Service
{
private:
					TaskService();
	virtual			~TaskService();

public:
	void			BroadCast(Event* evt);

protected:
	virtual void	OnReset();

private:
	typedef std::vector<Task*> TaskList;
	TaskList		m_TaskList;

private:
	friend class	Task;
	void			OnActivate(Task* task);
	void			OnDeactivate(Task* task);

private:
	friend class	GameApp;
	friend class	Service;
	void			MakeSystemTask(Task* task);
};

//////////////////////////////////////////////////////////////////////////